<template>
	<el-col :span="componentModel.col*6" v-show="visible">
		<el-row>
			<el-col :span="currentComponentModel.labelCol" class="field-label-div" v-if="!componentModel.noLabel">
				<label class="field-label">{{componentModel.label}}</label>
			</el-col>
			<el-col :span="currentComponentModel.fieldcol">
				<el-input size="mini" v-model="vue_model" type="password" v-if="componentModel.password==true"></el-input>
				<el-input size="mini" v-model="vue_model" v-else @change="onChangeHandler" :readonly="readonly">
				</el-input>
			</el-col>
		</el-row>
	</el-col>
</template>

<script>
	import {
		sendComponentValueChangeRequest
	} from '@/utils/requestUtils.js';
	import utils from '@/utils/utils.js';
	export default {
		name: "TextComponent",
		props: ["componentModel","data"],
		data() {
			return {
				vue_model: "",
				visible: true,
				readonly: false,
				label: "",
				"currentComponentModel":this.componentModel
			}
		},beforeMount() {
			if(this.componentModel.col==4){
				this.currentComponentModel.labelCol=4;
				this.currentComponentModel.fieldcol=20;
			}else{
				this.currentComponentModel.labelCol=8;
				this.currentComponentModel.fieldcol=16;
			}
		},
		inject:['children'],
		mounted() {
			this.children.push(this);
		},beforeUnmount() {
			utils.removeArrayElement(this.children,this);
		},
		methods: {
			getValue() {
				return this.vue_model;
			},
			setProp(prop) {
				for (var k in prop) {
					if (k == "value") {
						if (prop[k] == null) {
							this.vue_model = "";
						} else {
							this.vue_model = prop[k];
						}
					} else if (k == "visible") {
						this.visible = prop[k];
					} else if (k == "readonly") {
						this.readonly = prop[k];
					}else if(k=="label"){
						this.label = prop[k];
					}
				}
			},
			onChangeHandler() {
				if (this.scope != undefined) {
					this.$emit("onValueChange", this);
					return;
				}
				sendComponentValueChangeRequest(this);		
			}
		}
	}
</script>

<style>
</style>
